package mspbots.next.ticket.common;

import org.springframework.util.LinkedMultiValueMap;

import java.util.LinkedHashMap;

/**
 *  mspbots.next.ticket.common.QueryParams
 *
 * @author <a href="https://github.com/vnobo">Alex bob</a>
 * @date Created by 2020/8/19
 */
public class QueryParams extends LinkedMultiValueMap<String, String> {

    private String href;
    private int pageSize;
    private String conditions;
    private String orderBy;
    private String columns;

    /**
     * Create a new LinkedMultiValueMap that wraps a {@link LinkedHashMap}.
     */
    public QueryParams() {
        super(new LinkedHashMap<>());
        this.pageSize = 50;
        this.set("page", "0");
        this.set("pageSize", String.valueOf(this.pageSize));
        this.set("orderBy", "id asc");
    }

    /**
     * Create a new LinkedMultiValueMap that wraps a {@link LinkedHashMap}
     * with the given initial capacity.
     *
     * @param initialCapacity the initial capacity
     */
    public QueryParams(int initialCapacity) {
        super(new LinkedHashMap<>(initialCapacity));
    }


    /**
     * default query params
     * max records 500
     * page 0
     *
     * @return default query body
     */
    public static QueryParams withDefault() {
        QueryParams queryParams = new QueryParams(8);
        return queryParams.pageSize(50).orderBy("id desc");
    }


    public QueryParams pageSize(int pageSize) {
        this.setPageSize(pageSize);
        return this;
    }

    public QueryParams orderBy(String orderBy) {
        this.setOrderBy(orderBy);
        return this;
    }

    public QueryParams columns(String columns) {
        this.setColumns(columns);
        return this;
    }

    public QueryParams href(String href) {
        this.setHref(href);
        return this;
    }

    public QueryParams conditions(String conditions) {
        this.setConditions(conditions);
        return this;
    }

    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href;
        this.set("href", this.href);
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.set("pageSize",String.valueOf(pageSize));
        this.pageSize = pageSize;
    }

    public String getConditions() {
        return conditions;
    }

    public void setConditions(String conditions) {
        this.set("conditions", conditions);
        this.conditions = conditions;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.set("orderBy",orderBy);
        this.orderBy = orderBy;
    }

    public String getColumns() {
        return columns;
    }

    public void setColumns(String columns) {
        this.set("columns", columns);
        this.columns = columns;
    }
}
